package org.spring.springboot.controller;

import javax.servlet.http.HttpServletRequest;

import org.spring.springboot.entity.Student;
import org.spring.springboot.mapper.UserMapper;
import org.spring.springboot.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

//@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
@RequestMapping("/StudentController")
public class StudentController {
	
	@Autowired
    private StudentService studentService;
	
	//查询方式1
	@GetMapping("/selectStudentById")
	@ResponseBody
	public String selectStudentById(@RequestParam(value="id") int id) {
		return studentService.selectStudentById(id).toString();
	}
	
	//查询方式2
	@GetMapping("/selectById/{id}")
	@ResponseBody
	public String selectById(@PathVariable int id) {
		return studentService.selectStudentById(id).toString();
	}
	
	//新增
	@RequestMapping("/insertStudent")
	@ResponseBody
	public String insertStudent(HttpServletRequest request) {
		if (studentService.insertStudent()) {
			return "插入成功！";
		} else {
			return "插入失败！";
		}
	}
	
}
